//
//  SegmentControl.m
//  PlayerFix
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 DAT. All rights reserved.
//

#import "SegmentControl.h"
#import "RootViewController.h"
#import "MusicRootViewController.h"
@interface SegmentControl ()

@property(nonatomic,strong)MusicRootViewController *recommend;
@property(nonatomic,strong)RootViewController *rootVC;

@end

@implementation SegmentControl

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Menu" style:UIBarButtonItemStyleDone target:self action:@selector(presentLeftMenuViewController)];
    
    
    
    UISegmentedControl *segmentControl = [[UISegmentedControl alloc]initWithItems:[NSMutableArray arrayWithObjects:@"音乐",@"影视",nil]];
    self.navigationItem.titleView = segmentControl;
    [segmentControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    segmentControl.frame = CGRectMake(0, 0, 180 , 30);
    segmentControl.tintColor = [UIColor whiteColor];
    //初始化选中状态
    segmentControl.selectedSegmentIndex = 0;
    
    self.rootVC = [[RootViewController alloc]init];
    [self addChildViewController:self.rootVC];
    [self.view addSubview:self.rootVC.view];
    
    self.recommend = [[MusicRootViewController alloc]init];
    [self addChildViewController:self.recommend];
    [self.view addSubview:self.recommend.view];
//    self.recommend.tableView.scrollsToTop = NO;
    
    
}

-(void)segmentAction:(UISegmentedControl *)segment
{
    if (segment.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:self.recommend.view];
//        self.recommend.my.scrollsToTop = NO;//防止scrollsToTop功能冲突
//        self.recommend.tableView.scrollsToTop = YES;
    }else {
        [self.view bringSubviewToFront:self.rootVC.view];
//        self.classify.tableView.scrollsToTop = YES;
//        self.classify.tableView.scrollsToTop = NO;
        
    }
}

-(void)presentLeftMenuViewController
{
    ITRAirSideMenu *itrSideMenu = ((AppDelegate *)[UIApplication sharedApplication].delegate).itrAirSideMenu;
    [itrSideMenu presentLeftMenuViewController];
    
}

    
    
    


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
